package com.boot.proofing.common.util;/**
 * @description
 * @autor xbwu on 2018/7/2.
 */

import com.boot.proofing.mpweb.base.entity.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * web服务工具类
 * @author xbwu
 * @create 2018-07-02 
 **/
public class WebUtils {
    /**
     * 用户
     */
    private static ThreadLocal<User> userResource = new ThreadLocal<User>();

    public static User getUser() {
        return userResource.get();
    }

    public static void bindUser(User user) {
        userResource.set(user);
    }

    public static User unbindUser() {
        User obj = userResource.get();
        userResource.remove();
        return obj;
    }

    public static void setSessionAttribute(HttpServletRequest request,String name,Object value){
        HttpSession session = request.getSession();
        session.setAttribute(name,value);
    }
}
